How to Write a Case Statement

The case statement in MySQL is really easy to use, let’s take a look at the next example:

select 
	case
		when salary >= 100000 and salary<200000 then '100k'
		when salary >= 200000 then 'more than 200k'
		else 'under_100k'
	end AS salary_level,
    case
		when department IN ('human resources','accounting') then 'admin'
		when department IN ('engineering','IT') then 'tech'
		else 'other'
	end AS tasks
from employee;
salary_level tasks
100k admin
More than 200k tech
Under_100k admin

IN THIS PAGE